import { http } from "@/utils/http";

export interface PlaylistVO {
  id: string;
  name: string;
  description: string;
  userId: string | null;
  musicIds: string[] | null;
  category: string | null;
  createTime: string | null;
  updateTime: string | null;
  public: boolean | null;
}

export const playlistManageAPI = () => {
  // 获取歌单分页列表
  const getPlaylists = (): any => {
    return http.get(`/music/playlists/getAll`);
  };

  // 按名称搜索歌单
  const getPlaylistsByName = (name: string, page: number, rows: number): any => {
    return http.get(`playlist/page?name=${name}&page=${page}&rows=${rows}`);
  };

  // 创建歌单
  const addPlaylist = (data: PlaylistVO): any => {
    return http.post("music/playlists", data);
  };

  // 更新歌单信息
  const updatePlaylist = (data: PlaylistVO): any => {
    return http.put("music/playlists", data);
  };

  // 删除歌单
  const deletePlaylist = (id: string): any => {
    return http.delete(`music/playlists/${id}`);
  };

  // 添加音乐到歌单
  const addMusicToPlaylist = (playlistId: string, musicId: string): any => {
    return http.post(`music/playlists/${playlistId}/songs/${musicId}`);
  };

  // 从歌单移除音乐
  const removeMusicFromPlaylist = (playlistId: string, musicId: string): any => {
    return http.delete(`music/playlists/${playlistId}/songs/${musicId}`);
  };

  // 获取歌单中的音乐列表
  const getPlaylistMusics = (playlistId: string): any => {
    return http.get(`music/playlists/getMusicByPlaylistId?playlistId=${playlistId}`);
  };

    // 获得所有歌曲类型
    const getmusicType = (): any => {
      return http.get(`music/type/all`)
    }
  return {
    getPlaylists,
    getPlaylistsByName,
    addPlaylist,
    updatePlaylist,
    deletePlaylist,
    addMusicToPlaylist,
    removeMusicFromPlaylist,
    getPlaylistMusics,
    getmusicType
  };
};